package com.dao.impl;

import com.dao.EchartsService;
import com.entity.Echarts;
import com.entity.vo.CircleEchartsVO;
import com.util.JdbcUtil;
import com.util.PageUtil;

import java.sql.SQLException;
import java.util.List;

public class EchartsServiceImpl implements EchartsService {
	@Override
	public int insert(Echarts echarts) throws SQLException {
		return 0;
	}

	@Override
	public List<Echarts> queryData(Echarts echarts) throws IllegalAccessException, SQLException, InstantiationException {
		return null;
	}

	@Override
	public int update(Echarts echarts) throws SQLException {
		return 0;
	}

	@Override
	public int deleteById(Object id) throws SQLException {
		return 0;
	}

	@Override
	public PageUtil<Echarts> queryDataBypage(int currentPgae, int pageSize, Echarts echarts) throws IllegalAccessException, SQLException, InstantiationException {
		return null;
	}

	/**
	 * 查询顶部的数据展示
	 * @return
	 */
	@Override
	public Echarts getTop() throws SQLException, InstantiationException, IllegalAccessException {
		String sql = "select member1.userNum,songer1.songerNum,song1.songNum, songlist1.songListNum,comment1.commentNum\n" +
				"from (select count(*) as userNum from member where is_deleted = 0) member1,\n" +
				"(select count(*) as songerNum from songer where is_deleted = 0) songer1,\n" +
				"(select count(*) as songNum from song where is_deleted = 0) song1,\n" +
				"(select count(*) as songListNum from song_list where is_deleted = 0) songlist1,\n" +
				"(select count(*) as commentNum from `comment` where is_deleted = 0) comment1 ";
		List<Echarts> echarts = JdbcUtil.queryData(sql, Echarts.class, null);
		if(echarts.isEmpty()) {
			return new Echarts();
		}
		return echarts.get(0);
	}


	/**
	 * 获取用户的分布
	 * @return
	 */
	@Override
	public List<CircleEchartsVO> getEchartsCirle() throws SQLException, InstantiationException, IllegalAccessException {
		String sql = "select count(*) num,localtion address from member\n" +
				"where is_deleted = 0\n" +
				"group by localtion  limit 50 ";
		List<CircleEchartsVO> circleEchartsVOS = JdbcUtil.queryData(sql, CircleEchartsVO.class, null);
		return circleEchartsVOS;
	}
}
